package top.codecrab.eblog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.codecrab.eblog.entity.SignRule;
import top.codecrab.eblog.mapper.SignRuleMapper;
import top.codecrab.eblog.service.SignRuleService;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author codecrab
 * @since 2022-03-18
 */
@Service
public class SignRuleServiceImpl extends ServiceImpl<SignRuleMapper, SignRule> implements SignRuleService {

    @Override
    public Integer getPointByDays(Integer days) {
        // 按照天数从大到小排序，取小于等于指定天数的第一条
        Page<SignRule> signRulePage = baseMapper.selectPage(
            Page.of(1, 1, false),
            new QueryWrapper<SignRule>()
                .le("day", days)
                .orderByDesc("day")
        );

        return signRulePage.getRecords().get(0).getPoint();
    }
}
